home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Video Guide (RU) (pic).ifs < prev    next >
Encoding:
Text File  |  2004-03-20  |  15.6 KB  |  512 lines

  1. // GETINFO SCRIPTING
  2. // Imports russian movies info with small picture from VideoGuide
  3.  
  4. (***************************************************
  5.  *  Movie information import script for:           *
  6.  *    VideoGuide Russian,                          *
  7.  *    http://www.videoguide.ru/                    *
  8.  *                                                 *
  9.  *  (c) 2002 Yan Sorkin       ysorkin@mail.ru      *
  10.  *                                                 *
  11.  *  Last update:                                   *
  12.  *  - 26.11.2002                                   *
  13.  *                                                 *
  14.  *  Known issues:                                  *
  15.  *  - none                                         *
  16.  *                                                 *
  17.  *  For use with Ant Movie Catalog 3.4.0           *
  18.  *  www.antp.be/software/moviecatalog              *
  19.  *                                                 *
  20.  *  This program is free software; you can         *
  21.  *  redistribute it and/or modify it under the     *
  22.  *  terms of the GNU General Public License as     *
  23.  *  published by the Free Software Foundation;     *
  24.  *  either version 2 of the License, or (at your   *
  25.  *  option) any later version.                     *
  26.  ***************************************************)
  27.  
  28. program VideoGuide;
  29. const
  30.   BaseAddress = 'http://www.videoguide.ru/';
  31. //  BaseAddress = 'http://localhost/';
  32. var
  33.   MovieName: string;
  34.  
  35. function GetTextBlockFrom(Text: string; StartAt: string): string;
  36. var
  37.   TextBlock: string;
  38.   StartPos, EndPos: Integer;
  39. begin
  40.   TextBlock := Text;
  41.   StartPos := pos(StartAt, TextBlock);
  42.   if StartPos > 0 then
  43.   begin
  44.     Delete(TextBlock, 1, StartPos - 1);
  45.     result := TextBlock;
  46.   end;
  47. end;
  48.  
  49. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  50. var
  51.   i: Integer;
  52. begin
  53.   result := -1;
  54.   if StartAt < 0 then
  55.     StartAt := 0;
  56.   for i := StartAt to List.Count-1 do
  57.     if Pos(Pattern, List.GetString(i)) <> 0 then
  58.     begin
  59.       result := i;
  60.       Break;
  61.     end;
  62. end;
  63.  
  64. procedure AnalyzePage(Address: string);
  65. var
  66.   Page: TStringList;
  67.   LineNr: Integer;
  68.   Line: string;
  69.   TextBlock: string;
  70. begin
  71.   Page := TStringList.Create;
  72.   Page.Text := GetPage(Address);
  73.   if pos('<TITLE>┬ΦΣσε├ΦΣ(R) - ╧εΦ±Ω ⌠Φδⁿ∞α "', Page.Text) = 0 then
  74.   begin
  75.     SetField(fieldURL, Address);
  76.     if pos('<TITLE>┬ΦΣσε├ΦΣ(R) - ╨σδΦτ φα DVD', Page.Text) > 0 then
  77.     begin
  78.         AnalyzeVideoPage(Page);
  79.     end else
  80.     if pos('<TITLE>┬ΦΣσε├ΦΣ(R) - ╨σδΦτ φα ΓΦΣσε', Page.Text) > 0 then
  81.     begin
  82.         AnalyzeVideoPage(Page);
  83.     end else
  84.     begin
  85.         AnalyzeMoviePage(Page);
  86.     end;
  87.   end else
  88.   if pos('ReDirect("', Page.Text) > 0 then
  89.   begin
  90.     AnalyzeRedirectPage(Page);
  91.   end else
  92.   begin
  93.     PickTreeClear;
  94.     LineNr := FindLine('┬±σπε φαΘΣσφε ⌠Φδⁿ∞εΓ Γ ε±φεΓφεΘ ßατσ', Page, 0);
  95.     if LineNr > -1 then
  96.     begin
  97.       PickTreeAdd('Movies', '');
  98.       AddMoviesTitles(Page, LineNr);
  99.     end;
  100.     TextBlock := GetTextBlockFrom(Page.Text, '┬±σπε φαΘΣσφε ⌠Φδⁿ∞εΓ Γ ßατσ ΓΦΣσε≡σδΦτεΓ');
  101.     if Length(TextBlock) > 0 then
  102.     begin
  103.       PickTreeAdd('Released on video', '');
  104.       AddReleasesTitles(TextBlock);
  105.     end;
  106.     TextBlock := GetTextBlockFrom(Page.Text, '┬±σπε φαΘΣσφε ⌠Φδⁿ∞εΓ Γ ßατσ ≡σδΦτεΓ DVD');
  107.     if Length(TextBlock) > 0 then
  108.     begin
  109.       PickTreeAdd('Released on DVD', '');
  110.       AddReleasesTitles(TextBlock);
  111.     end;
  112.     LineNr := FindLine('╤∞. ≥αΩµσ:</b> ε±≥αΓ°Φσ±  <a href="', Page, LineNr);
  113.     if LineNr > -1 then
  114.     begin
  115.       AddFindMoreLink(Page, LineNr);
  116.     end;
  117.     if PickTreeExec(Address) then
  118.       AnalyzePage(Address);
  119.   end;
  120.   Page.Free;
  121. end;
  122.  
  123. procedure AnalyzeMoviePage(Page: TStringList);
  124. var
  125.   Line, Value, Value2, FullValue: string;
  126.   LineNr, MovieLength: Integer;
  127.   BeginPos, EndPos: Integer;
  128. begin
  129.  
  130.   // Original Title & Year
  131.   LineNr := FindLine('<TITLE>', Page, 0);
  132.   Line := Page.GetString(LineNr);
  133.   if LineNr > -1 then
  134.   begin
  135.     BeginPos := pos('<TITLE>┬ΦΣσε├ΦΣ(R) - ', Line);
  136.     if BeginPos > 0 then
  137.       BeginPos := BeginPos + 21;
  138.     EndPos := pos(' (', Line);
  139.     if EndPos = 0 then
  140.       EndPos := Length(Line);
  141.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  142.     HTMLDecode(Value);
  143.     Value := AnsiLowerCase(Value);
  144.     Value := AnsiUpFirstLetter(Value);
  145.     SetField(fieldOriginalTitle, Value);
  146.     BeginPos := pos(' ', Line) + 6;
  147.     if BeginPos > 0 then
  148.     begin
  149.       EndPos := Length(Line);
  150.       Value := copy(Line, BeginPos, EndPos - BeginPos);
  151.       BeginPos := pos('(', Value) + 1;
  152.       EndPos := pos(')', Value);
  153.       if (BeginPos > 0) and (EndPos > 0) then
  154.       begin
  155.         FullValue := copy(Value, BeginPos, EndPos - BeginPos);
  156.         SetField(fieldYear, FullValue);
  157.       end;
  158.     end;
  159.   end;
  160.  
  161.   // Director
  162.   LineNr := FindLine('╨σµΦ±±σ≡:', Page, 0);
  163.   if LineNr > -1 then
  164.   begin
  165.     Value := '';
  166.     Line := Page.GetString(LineNr);
  167.     BeginPos := pos('</B> ', Line) + 5;
  168.     EndPos := Length(Line);
  169.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  170.     HTMLDecode(Value);
  171.     HTMLRemoveTags(Value);
  172.     SetField(fieldDirector, Value);
  173.   end;
  174.  
  175.   // Actors
  176.   LineNr := FindLine('┬ ≡εδ ⌡:', Page, 0);
  177.   if LineNr > -1 then
  178.   begin
  179.     Value := '';
  180.     Line := Page.GetString(LineNr);
  181.     BeginPos := pos('</B> ', Line) + 5;
  182.     EndPos := Length(Line);
  183.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  184.     HTMLDecode(Value);
  185.     HTMLRemoveTags(Value);
  186.     SetField(fieldActors, Value);
  187.   end;
  188.  
  189.   //Country
  190.   LineNr := FindLine('<br><I>', Page, 0);
  191.   if LineNr > -1 then
  192.   begin
  193.     Line := Page.GetString(LineNr);
  194.     BeginPos := pos('<br><I>', Line) + 7;
  195.     EndPos := pos(' ', Line);
  196.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  197.     HTMLDecode(Value);
  198.     SetField(fieldCountry, Value);
  199.   end;
  200.  
  201.   //Category
  202.   LineNr := FindLine('IdGenre=', Page, 0);
  203.   if LineNr > -1 then
  204.   begin
  205.     Line := Page.GetString(LineNr);
  206.     BeginPos := pos('">', Line) + 2;
  207.     EndPos := pos('</a>', Line);
  208.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  209.     HTMLDecode(Value);
  210.     SetField(fieldCategory, Value);
  211.   end;
  212.  
  213.   //Year and Length - LineNr is from the previous search
  214.   if LineNr > -1 then
  215.   begin
  216.     Line := Page.GetString(LineNr + 2);
  217.     BeginPos := 1;
  218.     EndPos := pos('; ', Line);
  219.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  220.     HTMLRemoveTags(Value);
  221.     SetField(fieldYear, Value);
  222.     
  223.     BeginPos := pos('; ', Line) + 7;
  224.     EndPos := Length(Line);
  225.     Line := copy(Line, BeginPos, EndPos - BeginPos);
  226.     BeginPos := 1;
  227.     EndPos := pos(',', Line);
  228.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  229.     MovieLength := StrToInt(Value, 0) * 60;
  230.     BeginPos := EndPos + 1;
  231.     EndPos := pos(';&', Line);
  232.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  233.     MovieLength := MovieLength + StrToInt(Value, 0);
  234.     if MovieLength > 0 then
  235.       SetField(fieldLength, IntToStr(MovieLength));
  236.   end;
  237.  
  238.   //Description
  239.   Value2 := '<p align="JUSTIFY">';
  240.   LineNr := FindLine( Value2, Page, 0);
  241.   if LineNr = -1 then
  242.   begin
  243.     Value2 := '<p align=justify>';
  244.     LineNr := FindLine(Value2, Page, 0);
  245.   end;
  246.   if LineNr > -1 then
  247.   begin
  248.     Line := Page.GetString(LineNr);
  249.     BeginPos := pos(Value2, Line) + Length(Value2);
  250.     EndPos := Length(Line);
  251.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  252.     HTMLDecode(Value);
  253.     Value := StringReplace(Value, '<br>', #13#10);
  254.     Value := StringReplace(Value, '<BR>', #13#10);
  255.     Value := StringReplace(Value, '<p', #13#10#13#10 + '<p');
  256.     HTMLRemoveTags(Value);
  257.     SetField(fieldDescription, Value);
  258.   end;
  259.  
  260.   // Picture
  261.   LineNr := FindLine('<img src="\img\films\', Page, 0);
  262.   if LineNr = -1 then
  263.     LineNr := FindLine('<img src="/img/films/', Page, 0);
  264.   if LineNr > -1 then
  265.   begin
  266.     Line := Page.GetString(LineNr);
  267.     BeginPos := pos('src="', Line) + 4;
  268.     Delete(Line, 1, BeginPos);
  269.     EndPos := pos('"', Line);
  270.     Value := copy(Line, 1, EndPos - 1);
  271.     GetPicture(Value, False); // False = do not store picture externally ; store it in the catalog file
  272.   end;
  273.  
  274.   DisplayResults;
  275. end;
  276.  
  277. procedure AnalyzeVideoPage(Page: TStringList);
  278. var
  279.   Line, Value, Value2, FullValue: string;
  280.   LineNr, MovieLength: Integer;
  281.   BeginPos, EndPos: Integer;
  282. begin
  283.  
  284.   // Title, Original Title, Country, Year, Length, Category
  285.   LineNr := FindLine('<p><b><a href="card_film.asp?IDFilm=', Page, 0);
  286.   if LineNr = -1 then
  287.     LineNr := FindLine('<p><b><font color="Navy">', Page, 0);
  288.   if LineNr > -1 then
  289.   begin
  290.     Line := Page.GetString(LineNr);
  291.     // Title
  292.     BeginPos := pos('">', Line) + 2;
  293.     EndPos := pos('</b>', Line);
  294.     if EndPos = 0 then
  295.       EndPos := Length(Line);
  296.     FullValue := copy(Line, BeginPos, EndPos - BeginPos);
  297.     HTMLDecode(FullValue);
  298.     HTMLRemoveTags(FullValue);
  299.     FullValue := AnsiLowerCase(FullValue);
  300.     FullValue := AnsiUpFirstLetter(FullValue);
  301.     SetField(fieldOriginalTitle, FullValue);
  302.  
  303.     // Original Title (if exists)
  304.     BeginPos := pos('<br><small>/', Line) + 12;
  305.     EndPos := pos('/  ', Line);
  306.     if (BeginPos > 0) and (EndPos > 0) then
  307.     begin
  308.       Value := copy(Line, BeginPos, EndPos - BeginPos);
  309.       HTMLDecode(Value);
  310.       HTMLRemoveTags(Value);
  311.       Value := AnsiLowerCase(Value);
  312.       Value := AnsiMixedCase(Value, ' .-');
  313.       SetField(fieldOriginalTitle, Value);
  314.       SetField(fieldTranslatedTitle, FullValue);
  315.       Delete(Line, 1, EndPos + 7);
  316.     end;
  317.     
  318.     // Country
  319.     BeginPos := pos('<br><small>', Line);
  320.     if BeginPos = 0 then
  321.       BeginPos := 1;
  322.     EndPos := pos('  ', Line);
  323.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  324.     HTMLDecode(Value);
  325.     HTMLRemoveTags(Value);
  326.     SetField(fieldCountry, Value);
  327.     Delete(Line, 1, EndPos + 6);
  328.  
  329.     // Year and Length
  330.     BeginPos := 1;
  331.     EndPos := pos('  ', Line);
  332.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  333.     SetField(fieldYear, Value);
  334.     
  335.     BeginPos := pos('  ', Line) + 7;
  336.     EndPos := pos(' ∞Φφ', Line);
  337.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  338.     SetField(fieldLength, Value);
  339.   end;
  340.  
  341.   //Category
  342.   LineNr := FindLine('</small><br>', Page, 0);
  343.   if LineNr > -1 then
  344.   begin
  345.     Line := Page.GetString(LineNr);
  346.     BeginPos := pos('</small><br>', Line) + 12;
  347.     EndPos := Length(Line) + 1;
  348.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  349.     HTMLDecode(Value);
  350.     SetField(fieldCategory, Value);
  351.   end;
  352.  
  353.   // Director
  354.   LineNr := FindLine('╨σµΦ±±σ≡:', Page, 0);
  355.   if LineNr > -1 then
  356.   begin
  357.     Line := Page.GetString(LineNr);
  358.     BeginPos := pos('</b> ', Line) + 5;
  359.     EndPos := Length(Line) + 1;
  360.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  361.     HTMLDecode(Value);
  362.     HTMLRemoveTags(Value);
  363.     SetField(fieldDirector, Value);
  364.   end;
  365.  
  366.   // Actors
  367.   LineNr := FindLine('<BR><b>┬ ≡εδ ⌡:</b>', Page, 0);
  368.   if LineNr > -1 then
  369.   begin
  370.     Line := Page.GetString(LineNr);
  371.     BeginPos := pos('</b>  ', Line) + 6;
  372.     EndPos := Length(Line);
  373.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  374.     HTMLDecode(Value);
  375.     HTMLRemoveTags(Value);
  376.     SetField(fieldActors, Value);
  377.   end;
  378.  
  379.   //Description
  380.   LineNr := FindLine('<p align="JUSTIFY">', Page, 0);
  381.   if LineNr > -1 then
  382.   begin
  383.     Line := Page.GetString(LineNr);
  384.     BeginPos := pos('<p align="JUSTIFY">', Line) + 19;
  385.     EndPos := Length(Line);
  386.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  387.     HTMLDecode(Value);
  388.     Value := StringReplace(Value, '<br>', #13#10);
  389.     Value := StringReplace(Value, '<BR>', #13#10);
  390.     Value := StringReplace(Value, '<p', #13#10#13#10 + '<p');
  391.     HTMLRemoveTags(Value);
  392.     SetField(fieldDescription, Value);
  393.   end;
  394.  
  395.   // Picture
  396.   LineNr := FindLine('<img src="\img\films\', Page, 0);
  397.   if LineNr = -1 then
  398.     LineNr := FindLine('<img src="/img/films/', Page, 0);
  399.   if LineNr = -1 then
  400.     LineNr := FindLine('<img src="\img\rel\', Page, 0);
  401.   if LineNr = -1 then
  402.     LineNr := FindLine('<img src="/img/rel/', Page, 0);
  403.   if LineNr = -1 then
  404.     LineNr := FindLine('<img src="\img\dvd\', Page, 0);
  405.   if LineNr = -1 then
  406.     LineNr := FindLine('<img src="/img/dvd/', Page, 0);
  407.   if LineNr > -1 then
  408.   begin
  409.     Line := Page.GetString(LineNr);
  410.     BeginPos := pos('src="', Line) + 4;
  411.     Delete(Line, 1, BeginPos);
  412.     EndPos := pos('"', Line);
  413.     Value := copy(Line, 1, EndPos - 1);
  414.     GetPicture(Value, False); // False = do not store picture externally ; store it in the catalog file
  415.   end;
  416.  
  417.   DisplayResults;
  418. end;
  419.  
  420. procedure AnalyzeRedirectPage(Page: TStringList);
  421. var
  422.   Address: string;
  423.   BeginPos, EndPos: Integer;
  424. begin
  425.   BeginPos := pos('ReDirect("', Page.Text) + 10;
  426.   EndPos := pos('")</script>', Page.Text);
  427.   Address := BaseAddress + copy(Page.Text, BeginPos, EndPos - BeginPos);
  428.   AnalyzePage(Address);
  429. end;
  430.  
  431. procedure AddFindMoreLink(Page: TStringList; var LineNr: Integer);
  432. var
  433.   Line, Value, Address: string;
  434.   StartPos, EndPos: Integer;
  435. begin
  436.   Line := Page.GetString(LineNr);
  437.   StartPos := pos('╤∞. ≥αΩµσ:</b> ε±≥αΓ°Φσ±  <a href="', Line) + 35;
  438.   EndPos := pos('</a> ⌠Φδⁿ∞', Line);
  439.   Value := copy(Line, StartPos, EndPos - StartPos);
  440.   StartPos := 1;
  441.   EndPos := pos('">', Value);
  442.   Address := BaseAddress + copy(Value, StartPos, EndPos - StartPos);
  443.   PickTreeMoreLink(Address);
  444. end;
  445.  
  446. procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
  447. var
  448.   Line: string;
  449.   MovieTitle, MovieAddress: string;
  450.   StartPos, EndPos: Integer;
  451. begin
  452.   repeat
  453.     LineNr := LineNr + 1;
  454.     Line := Page.GetString(LineNr);
  455.     StartPos := pos('="', Line);
  456.     EndPos := pos('</OL>', Line);
  457.     if (StartPos > 0) and (EndPos = 0) then
  458.     begin
  459.       StartPos := StartPos + 2;
  460.       MovieAddress := copy(Line, StartPos, pos('">', Line) - StartPos);
  461.       StartPos := pos('">', Line) + 2;
  462.       MovieTitle := copy(Line, StartPos, pos('</a>', Line) - StartPos);
  463.       Line := Page.GetString(LineNr + 1);
  464.       MovieTitle := MovieTitle + copy(Line, 1, pos('</small>', Line) - 1);
  465.       HTMLDecode(Movietitle);
  466.       HTMLRemoveTags(MovieTitle);
  467.       PickTreeAdd(MovieTitle, BaseAddress + MovieAddress);
  468.     end;
  469.   until EndPos > 0;
  470. end;
  471.  
  472. procedure AddReleasesTitles(TextBlock: string);
  473. var
  474.   MovieTitle, MovieAddress: string;
  475.   StartPos, EndPos, EndTablePos: Integer;
  476. begin
  477.   repeat
  478.     StartPos := pos('<td><b><a href="', TextBlock);
  479.     EndTablePos :=  pos('</table>', TextBlock);
  480.     if StartPos > 0 then
  481.     begin
  482.       Delete(TextBlock, 1, StartPos - 1);
  483.     end;
  484.     if (StartPos > 0) and (StartPos < EndTablePos) then
  485.     begin
  486.       EndPos := pos('</td>', TextBlock);
  487.       MovieTitle := copy(TextBlock, 1, EndPos - 1);
  488.       HTMLDecode(MovieTitle);
  489.       HTMLRemoveTags(MovieTitle);
  490.       MovieAddress := copy(TextBlock, 17, pos('">', TextBlock) - 17);
  491.       PickTreeAdd(MovieTitle, BaseAddress + MovieAddress);
  492.       Delete(TextBlock, 1, EndPos - 1);
  493.     end;
  494.   until (StartPos = 0) or (StartPos > EndTablePos);
  495. end;
  496.  
  497. begin
  498.   if CheckVersion(3,4,0) then
  499.   begin
  500.     MovieName := GetField(fieldOriginalTitle);
  501.     if MovieName = '' then
  502.       MovieName := GetField(fieldTranslatedTitle);
  503.     if Input('Import from VideoGuide', 'Enter the title of the movie:', MovieName) then
  504.     begin
  505.       AnalyzePage('http://www.videoguide.ru/find.asp?Search=Simple&types=film&titles='+UrlEncode(MovieName));
  506. //      AnalyzePage('http://localhost/search1.htm');
  507.     end;
  508.   end else
  509.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
  510. end.
  511.  
  512.